//
//  VisitorLoginView.swift
//  新浪微博
//
//  Created by apple on 15/7/28.
//  Copyright © 2015年 Adam. All rights reserved.
//

import UIKit

class VisitorLoginView: UIView {
 
    // 设置视图信息
    func setupInfo(isHome:Bool,imageName:String,message:String){
     messageLabel.text=message
        iconView.image=UIImage(named: imageName)
        if !isHome{
           houseView.hidden=true
            sendSubviewToBack(maskIconView)
        }
    }
    
      //界面初始化
   override init(frame: CGRect) {
    super.init(frame:frame)
    setUpUI()
    backgroundColor=UIColor(white: 0.93, alpha: 1.0)
    }
    
    required init?(coder aDecoder: NSCoder) {
        //fatalError("init(coder:) has not been implemented")
      super.init(coder: aDecoder)
        backgroundColor=UIColor(white: 0.93, alpha: 1.0)
      setUpUI()
    }
    
    private func setUpUI(){
        addSubview(iconView)
        addSubview(maskIconView)
        addSubview(houseView)
        addSubview(registerButton)
        addSubview(loginButton)
        addSubview(messageLabel)  
        
     //用代码设置自动布局
        iconView.translatesAutoresizingMaskIntoConstraints=false
        addConstraint(NSLayoutConstraint(item: iconView, attribute: NSLayoutAttribute.CenterX, relatedBy: NSLayoutRelation.Equal, toItem: self, attribute: NSLayoutAttribute.CenterX, multiplier: 1.0, constant: 0))
       addConstraint( NSLayoutConstraint(item: iconView, attribute: NSLayoutAttribute.CenterY, relatedBy: NSLayoutRelation.Equal, toItem: self, attribute: NSLayoutAttribute.CenterY, multiplier: 1.0, constant: -60))
        
        houseView.translatesAutoresizingMaskIntoConstraints=false
        addConstraint(NSLayoutConstraint(item: houseView, attribute: NSLayoutAttribute.CenterX, relatedBy: NSLayoutRelation.Equal, toItem: iconView, attribute: NSLayoutAttribute.CenterX, multiplier: 1.0, constant: 0))
        addConstraint(NSLayoutConstraint(item: houseView, attribute: NSLayoutAttribute.CenterY, relatedBy: NSLayoutRelation.Equal, toItem: iconView, attribute: NSLayoutAttribute.CenterY, multiplier: 1.0, constant: 0))
        
        messageLabel.translatesAutoresizingMaskIntoConstraints=false
        addConstraint(NSLayoutConstraint(item: messageLabel, attribute: NSLayoutAttribute.CenterX, relatedBy: NSLayoutRelation.Equal, toItem: iconView, attribute: NSLayoutAttribute.CenterX, multiplier: 1.0, constant: 0))
        addConstraint(NSLayoutConstraint(item: messageLabel, attribute: NSLayoutAttribute.Top, relatedBy: NSLayoutRelation.Equal, toItem: iconView, attribute: NSLayoutAttribute.Bottom, multiplier: 1.0, constant: 16))
        //设置文本宽度的约束
        addConstraint(NSLayoutConstraint(item: messageLabel, attribute: NSLayoutAttribute.Width, relatedBy: NSLayoutRelation.Equal, toItem: nil, attribute: NSLayoutAttribute.NotAnAttribute, multiplier: 1.0, constant: 224))
        
        //设置注册按钮的自动布局
        registerButton.translatesAutoresizingMaskIntoConstraints=false
        addConstraint(NSLayoutConstraint(item:registerButton, attribute: NSLayoutAttribute.Left, relatedBy: NSLayoutRelation.Equal, toItem: messageLabel, attribute: NSLayoutAttribute.Left, multiplier: 1.0, constant: 0))
        addConstraint(NSLayoutConstraint(item:registerButton, attribute: NSLayoutAttribute.Top, relatedBy: NSLayoutRelation.Equal, toItem: messageLabel, attribute: NSLayoutAttribute.Bottom, multiplier: 1.0, constant: 16))
        
        addConstraint(NSLayoutConstraint(item:registerButton, attribute: NSLayoutAttribute.Width, relatedBy: NSLayoutRelation.Equal, toItem: nil, attribute: NSLayoutAttribute.NotAnAttribute, multiplier: 1.0, constant: 100))
        addConstraint(NSLayoutConstraint(item:registerButton, attribute: NSLayoutAttribute.Height, relatedBy: NSLayoutRelation.Equal, toItem: nil, attribute: NSLayoutAttribute.NotAnAttribute, multiplier: 1.0, constant: 35))
        
        loginButton.translatesAutoresizingMaskIntoConstraints=false
        addConstraint(NSLayoutConstraint(item:loginButton, attribute: NSLayoutAttribute.Right, relatedBy: NSLayoutRelation.Equal, toItem: messageLabel, attribute: NSLayoutAttribute.Right, multiplier: 1.0, constant: 0))
        addConstraint(NSLayoutConstraint(item:loginButton, attribute: NSLayoutAttribute.Top, relatedBy: NSLayoutRelation.Equal, toItem: messageLabel, attribute: NSLayoutAttribute.Bottom, multiplier: 1.0, constant: 16))
        
        addConstraint(NSLayoutConstraint(item:loginButton, attribute: NSLayoutAttribute.Width, relatedBy: NSLayoutRelation.Equal, toItem: nil, attribute: NSLayoutAttribute.NotAnAttribute, multiplier: 1.0, constant: 100))
        addConstraint(NSLayoutConstraint(item:loginButton, attribute: NSLayoutAttribute.Height, relatedBy: NSLayoutRelation.Equal, toItem: nil, attribute: NSLayoutAttribute.NotAnAttribute, multiplier: 1.0, constant: 35))
        //遮罩图片的布局
        maskIconView.translatesAutoresizingMaskIntoConstraints=false
    addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|-0-[maskView]-0-|", options: NSLayoutFormatOptions(rawValue: 0), metrics: nil, views: ["maskView": maskIconView]))
  addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:|-0-[maskView]-200-|", options: NSLayoutFormatOptions(rawValue: 0), metrics: nil, views: ["maskView": maskIconView]))
    }
    
    //懒加载控件
    private lazy var iconView:UIImageView={
       let vi=UIImageView(image:UIImage(named: "visitordiscover_feed_image_smallicon"))
        return vi
    }()
    //遮罩
    private lazy var maskIconView:UIImageView={
        let  maskView=UIImageView(image:UIImage(named: "visitordiscover_feed_mask_smallicon"))
        return maskView
    }()
    //小房子
    private lazy var houseView:UIImageView={
     let house=UIImageView(image: UIImage(named: "visitordiscover_feed_image_house"))
        return house
    }()
    private  lazy var  messageLabel:UILabel={
      let messageBl=UILabel()
        //messageBl.text="关注一些人，回来看看有哪些惊喜"
        messageBl.textColor=UIColor.darkGrayColor()
        messageBl.font=UIFont.systemFontOfSize(14)
        messageBl.textAlignment=NSTextAlignment.Center
        messageBl.numberOfLines=0
        messageBl.sizeToFit()
        return messageBl
    }()
    private lazy var registerButton:UIButton={
        let  registerBtn=UIButton()
        registerBtn.setTitle("注册", forState:UIControlState.Normal)
        registerBtn.setBackgroundImage(UIImage(named:"common_button_white_disable"), forState: UIControlState.Normal)
        registerBtn.setTitleColor(UIColor.orangeColor(), forState: UIControlState.Normal)
        registerBtn.addTarget(self, action: "register", forControlEvents: UIControlEvents.TouchUpInside)
        return registerBtn
    }()
    private func register(){
        print("注册")
    }
    private func login(){
        print("登录")
    }

    private lazy var loginButton:UIButton={
        let  loginBtn=UIButton()
        loginBtn.setTitle("登录", forState: UIControlState.Normal)
        loginBtn.setBackgroundImage(UIImage(named: "common_button_white_disable"), forState: UIControlState.Normal)
        loginBtn.setTitleColor(UIColor.darkGrayColor(), forState: UIControlState.Normal)
        loginBtn.addTarget(self, action: "login", forControlEvents: UIControlEvents.TouchUpInside)
        return loginBtn
        }()

   }
